//
//  MCDiscountPayCell.swift
//  StoreManage
//
//  Created by MC on 2017/12/19.
//  Copyright © 2017年 MC. All rights reserved.
//

import UIKit

class MCDiscountPayCell: UITableViewCell {

    private var tempModel : MCDiscountPayModel? = MCDiscountPayModel()
    
    var model : MCDiscountPayModel {
        get {
            return tempModel!
        }
        
        set {
            tempModel = newValue
            
            orderView.rightLabel.text = model.orderSn
            storeView.rightLabel.text = model.storeName
            readMoneyView.rightLabel.text =  MCString_judgemantDecimalsIsZero(figure: model.totalFee)
            accountView.rightLabel.text = MCString_judgemantDecimalsIsZero(figure: model.arrivalFrr)
            orderNoView.rightLabel.text = model.recipSn
            timeView.rightLabel.text = model.orderTime
            
            
            if model.orderType == 0 {
                orderTypeView.rightLabel.text = "优惠买单"
            } else {
                orderTypeView.rightLabel.text = "扫码支付"
            }
            
            
            switch model.payType {
            case 1:
                payWayView.rightLabel.text = "微信支付"
                break
            case 2:
                payWayView.rightLabel.text = "支付宝支付"
                break
            case 3:
                payWayView.rightLabel.text = "公众号支付"
                break
            case 4:
                payWayView.rightLabel.text = "景豆支付"
                break
            case 5:
                payWayView.rightLabel.text = "蚂蚁钱包支付"
                break
            case 6:
                payWayView.rightLabel.text = "支付宝网页支付"
                break
            default:
                break
            }
            
            
        }
    }
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        backgroundColor = UIColor.MCGray_light
        
        self.addSubview(orderView)
        orderView.snp.remakeConstraints { (make) ->Void in
            make.left.right.equalTo(self)
            make.top.equalTo(self)
            make.height.equalTo(40)
        }
        
        self.addSubview(storeView)
        storeView.snp.remakeConstraints { (make) ->Void in
            make.left.right.equalTo(self)
            make.top.equalTo(orderView.snp.bottom)
            make.height.equalTo(40)
        }
        
        self.addSubview(readMoneyView)
        readMoneyView.snp.remakeConstraints { (make) ->Void in
            make.left.right.equalTo(self)
            make.top.equalTo(storeView.snp.bottom)
            make.height.equalTo(40)
        }

        
        self.addSubview(accountView)
        accountView.snp.remakeConstraints { (make) ->Void in
            make.left.right.equalTo(self)
            make.top.equalTo(readMoneyView.snp.bottom)
            make.height.equalTo(40)
        }


        self.addSubview(orderTypeView)
        orderTypeView.snp.remakeConstraints { (make) ->Void in
            make.left.right.equalTo(self)
            make.top.equalTo(accountView.snp.bottom)
            make.height.equalTo(40)
        }


        self.addSubview(payWayView)
        payWayView.snp.remakeConstraints { (make) ->Void in
            make.left.right.equalTo(self)
            make.top.equalTo(orderTypeView.snp.bottom)
            make.height.equalTo(40)
        }


        self.addSubview(orderNoView)
        orderNoView.snp.remakeConstraints { (make) ->Void in
            make.left.right.equalTo(self)
            make.top.equalTo(payWayView.snp.bottom)
            make.height.equalTo(40)
        }


        self.addSubview(timeView)
        timeView.snp.remakeConstraints { (make) ->Void in
            make.left.right.equalTo(self)
            make.top.equalTo(orderNoView.snp.bottom)
            make.height.equalTo(40)
        }

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
    
    lazy var orderView: MCDiscountPayCellItemView = {
        let view = MCDiscountPayCellItemView()
        view.leftLabel.text = "订单编号："
        return view
    }()
    
    lazy var storeView: MCDiscountPayCellItemView = {
        let view = MCDiscountPayCellItemView()
        view.leftLabel.text = "店铺名称："
        return view
    }()

    
    lazy var readMoneyView: MCDiscountPayCellItemView = {
        let view = MCDiscountPayCellItemView()
        view.leftLabel.text = "实付金额："
        view.rightLabel.textColor = UIColor.red
        return view
    }()

    
    lazy var accountView: MCDiscountPayCellItemView = {
        let view = MCDiscountPayCellItemView()
        view.leftLabel.text = "到账金额："
        view.rightLabel.textColor = UIColor.red
        return view
    }()

    
    lazy var orderTypeView: MCDiscountPayCellItemView = {
        let view = MCDiscountPayCellItemView()
        view.leftLabel.text = "订单类型："
        return view
    }()

    
    lazy var payWayView: MCDiscountPayCellItemView = {
        let view = MCDiscountPayCellItemView()
        view.leftLabel.text = "支付方式："
        return view
    }()

    
    lazy var orderNoView: MCDiscountPayCellItemView = {
        let view = MCDiscountPayCellItemView()
        view.leftLabel.text = "收货编号："
        return view
    }()

    
    lazy var timeView: MCDiscountPayCellItemView = {
        let view = MCDiscountPayCellItemView()
        view.leftLabel.text = "订单时间："
        return view
    }()

}


class MCDiscountPayCellItemView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.white
        self.addSubview(leftLabel)
        leftLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(15)
            make.top.bottom.equalTo(self)
        }
        
        self.addSubview(rightLabel)
        rightLabel.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(-15)
            make.top.bottom.equalTo(self)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    public lazy var leftLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(14)
        label.textColor = UIColor.MCBlack
        return label
    }()
    
    public lazy var rightLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(14)
        label.textColor = UIColor.MCBlack
        return label
    }()
}
